package lab3;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JFrame;
import javax.swing.JPanel;

/**
* A class for drawing a graph.
* ( it's really only drawing text and lines and have no idea what it is drawing)
* @author Original map drawing is thanks to Tommi Kerola and Marcus Johansson IT students 2010
* @author changes by Erland Holmström 2010
* @TODO måste kunna rita riktade grafer
*/
public class DrawGraph extends JFrame {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@SuppressWarnings("unused")
	private int width;
	@SuppressWarnings("unused")
	private int heigth; 
	private JPanel panel;
	private Graphics g;
	
	public DrawGraph() {
		this(1300, 750); // passar bra för vårt linjenät
	}
	
	public DrawGraph(int width, int height) {
		this.width = width;
		this.heigth = height;
		panel = new JPanel();
		panel.setPreferredSize(new Dimension(width, height));
		panel.setLayout(null);
		add(panel);
		pack();
		setVisible(true);		
		g = panel.getGraphics();
	}
	
	public void drawString(String text, int x, int y) {
		x = scaleX(x)+8;
		y = scaleY(y);
		g.setColor(Color.black);
		g.fillOval(x-8, y-6, 3, 3);
		g.drawString(text, x, y); 
	}
	
	public void drawLine(int x1, int y1, int x2, int y2, Color color, double width) {
		x1 = scaleX(x1);
		y1 = scaleY(y1);
		x2 = scaleX(x2);
		y2 = scaleY(y2);
		g.setColor(color);
		((Graphics2D)g).setStroke(new BasicStroke( (float)width ));
		g.drawLine(x1, y1, x2, y2);
	}
	
	private int scaleX(int x) {
		return (int)(x*4)+10;
	}
	
	private int scaleY(int y) {
		return (int)(y*1.5) + 11;
	}
}
